package com.qqgame.hlddz;

import android.annotation.SuppressLint;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.widget.EditText;
import android.widget.Toast;

import androidx.appcompat.app.AppCompatActivity;

import com.qqgame.hlddz.databinding.ActivitySettingsBinding;

public class SettingsActivity extends AppCompatActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        com.qqgame.hlddz.databinding.ActivitySettingsBinding binding = ActivitySettingsBinding.inflate(getLayoutInflater());
        setContentView(binding.getRoot());

        showData();

        binding.save.setOnClickListener(view -> saveData());

    }



    @Override
    protected void onResume() {
        super.onResume();
        showData();
    }

    @SuppressLint("SetTextI18n")
    private void showData() {

        SharedPreferences sharedPreferences = getSharedPreferences("MyPreferences", MODE_PRIVATE);

        String display2AppValue = sharedPreferences.getString("display2App", "");
        EditText display2App = findViewById(R.id.display2App);
        display2App.setText(display2AppValue);

        String naviAppValue = sharedPreferences.getString("naviApp", "");
        EditText naviApp = findViewById(R.id.naviApp);
        naviApp.setText(naviAppValue);

        String poiALat1 = sharedPreferences.getString("poiALat", "");
        EditText poiALat = findViewById(R.id.poiALat);
        poiALat.setText(poiALat1);

        String poiALon1 = sharedPreferences.getString("poiALon", "");
        EditText poiALon = findViewById(R.id.poiALon);
        poiALon.setText(poiALon1);

        String poiAName1 = sharedPreferences.getString("poiAName", "");
        EditText poiAName = findViewById(R.id.poiAName);
        poiAName.setText(poiAName1);

        String poiBLat1 = sharedPreferences.getString("poiBLat", "");
        EditText poiBLat = findViewById(R.id.poiBLat);
        poiBLat.setText(poiBLat1);

        String poiBLon1 = sharedPreferences.getString("poiBLon", "");
        EditText poiBLon = findViewById(R.id.poiBLon);
        poiBLon.setText(poiBLon1);

        String poiBName1 = sharedPreferences.getString("poiBName", "");
        EditText poiBName = findViewById(R.id.poiBName);
        poiBName.setText(poiBName1);

        String poiCLat1 = sharedPreferences.getString("poiCLat", "");
        EditText poiCLat = findViewById(R.id.poiCLat);
        poiCLat.setText(poiCLat1);

        String poiCLon1 = sharedPreferences.getString("poiCLon", "");
        EditText poiCLon = findViewById(R.id.poiCLon);
        poiCLon.setText(poiCLon1);

        String poiCName1 = sharedPreferences.getString("poiCName", "");
        EditText poiCName = findViewById(R.id.poiCName);
        poiCName.setText(poiCName1);

        String poiDLat1 = sharedPreferences.getString("poiDLat", "");
        EditText poiDLat = findViewById(R.id.poiDLat);
        poiDLat.setText(poiDLat1);

        String poiDLon1 = sharedPreferences.getString("poiDLon", "");
        EditText poiDLon = findViewById(R.id.poiDLon);
        poiDLon.setText(poiDLon1);

        String poiDName1 = sharedPreferences.getString("poiDName", "");
        EditText poiDName = findViewById(R.id.poiDName);
        poiDName.setText(poiDName1);

        String poiELat1 = sharedPreferences.getString("poiELat", "");
        EditText poiELat = findViewById(R.id.poiELat);
        poiELat.setText(poiELat1);

        String poiELon1 = sharedPreferences.getString("poiELon", "");
        EditText poiELon = findViewById(R.id.poiELon);
        poiELon.setText(poiELon1);

        String poiEName1 = sharedPreferences.getString("poiEName", "");
        EditText poiEName = findViewById(R.id.poiEName);
        poiEName.setText(poiEName1);

    }

    private void saveData(){
        SharedPreferences sharedPreferences = getSharedPreferences("MyPreferences", MODE_PRIVATE);
        SharedPreferences.Editor editor = sharedPreferences.edit();

        EditText display2App = findViewById(R.id.display2App);
        editor.putString("display2App", display2App.getText().toString());

        EditText naviApp = findViewById(R.id.naviApp);
        editor.putString("naviApp", naviApp.getText().toString());

        EditText poiALat = findViewById(R.id.poiALat);
        editor.putString("poiALat", poiALat.getText().toString());

        EditText poiALon = findViewById(R.id.poiALon);
        editor.putString("poiALon", poiALon.getText().toString());

        EditText poiAName = findViewById(R.id.poiAName);
        editor.putString("poiAName", poiAName.getText().toString());

        EditText poiBLat = findViewById(R.id.poiBLat);
        editor.putString("poiBLat", poiBLat.getText().toString());

        EditText poiBLon = findViewById(R.id.poiBLon);
        editor.putString("poiBLon", poiBLon.getText().toString());

        EditText poiBName = findViewById(R.id.poiBName);
        editor.putString("poiBName", poiBName.getText().toString());

        EditText poiCLat = findViewById(R.id.poiCLat);
        editor.putString("poiCLat", poiCLat.getText().toString());

        EditText poiCLon = findViewById(R.id.poiCLon);
        editor.putString("poiCLon", poiCLon.getText().toString());

        EditText poiCName = findViewById(R.id.poiCName);
        editor.putString("poiCName", poiCName.getText().toString());

        EditText poiDLat = findViewById(R.id.poiDLat);
        editor.putString("poiDLat", poiDLat.getText().toString());

        EditText poiDLon = findViewById(R.id.poiDLon);
        editor.putString("poiDLon", poiDLon.getText().toString());

        EditText poiDName = findViewById(R.id.poiDName);
        editor.putString("poiDName", poiDName.getText().toString());

        EditText poiELat = findViewById(R.id.poiELat);
        editor.putString("poiELat", poiELat.getText().toString());

        EditText poiELon = findViewById(R.id.poiELon);
        editor.putString("poiELon", poiELon.getText().toString());

        EditText poiEName = findViewById(R.id.poiEName);
        editor.putString("poiEName", poiEName.getText().toString());

        editor.apply();

        Toast.makeText(this, "保存成功！", Toast.LENGTH_SHORT).show();

        finish();
    }


}